package com;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @Package: com.bj58.ehr.corehr.entity.workflow
 * @ClassName: SalaryMeasurementConfig
 * @Author: wulongkai
 * @CreateTime: 2023/10/26 11:51
 * @Description:
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SalaryMeasurementConfig {

    /**
     * 薪资测算模块权限(薪酬类角色id  ,分隔)
     */
    private String securityGroupRoleIds;

    /**
     * 基本工资（元/月）涨幅
     */
    SalaryFieldConfig basicSalaryIncrease;
    /**
     * 绩效（元/月）涨幅
     */
    SalaryFieldConfig performanceIncrease;
    /**
     * 年终奖（元/年）涨幅
     */
    SalaryFieldConfig yearEndBonusIncrease;
    /**
     * 年度目标总现金（TTC）（元/年）涨幅
     */
    @JsonProperty("TTCIncrease")
    SalaryFieldConfig TTCIncrease;
    /**
     * 股票期权（元/年）涨幅
     */
    SalaryFieldConfig shareIncrease;
    /**
     * 年度目标总收入（TP）（元/年）涨幅
     */
    SalaryFieldConfig totalIncomeIncrease;


    /**
     * 补助/其他薪资（元/年）
     */
    SalaryFieldConfig otherSalaryMeasurePrice;

    /**
     * 集团股票期权测算价格（元/股）
     */
    SalaryFieldConfig groupShareMeasurePrice;

    /**
     * 房产股票期权测算价格（元/股）
     */
    SalaryFieldConfig houseShareMeasurePrice;


    // 默认配置，前端展示
    public static SalaryMeasurementConfig getDefaultConfig() {
        SalaryMeasurementConfig defaultConfig = new SalaryMeasurementConfig();

        SalaryFieldConfig basicSalaryIncrease = new SalaryFieldConfig();
        basicSalaryIncrease.setField("basicSalaryIncrease");
        basicSalaryIncrease.setFieldName("基本工资涨幅");
        basicSalaryIncrease.setType(1);
        basicSalaryIncrease.setFrontShowName("基本工资（元/月）");
        basicSalaryIncrease.setShouldMeasurement(true);
        defaultConfig.setBasicSalaryIncrease(basicSalaryIncrease);

        SalaryFieldConfig performanceIncrease = new SalaryFieldConfig();
        performanceIncrease.setField("performanceIncrease");
        performanceIncrease.setFieldName("绩效涨幅");
        performanceIncrease.setType(1);
        performanceIncrease.setFrontShowName("绩效（元/月）");
        performanceIncrease.setShouldMeasurement(true);
        defaultConfig.setPerformanceIncrease(performanceIncrease);

        SalaryFieldConfig yearEndBonusIncrease = new SalaryFieldConfig();
        yearEndBonusIncrease.setField("yearEndBonusIncrease");
        yearEndBonusIncrease.setFieldName("年终奖涨幅");
        yearEndBonusIncrease.setType(1);
        yearEndBonusIncrease.setFrontShowName("年终奖（元/年）");
        yearEndBonusIncrease.setShouldMeasurement(true);
        defaultConfig.setYearEndBonusIncrease(yearEndBonusIncrease);

        SalaryFieldConfig TTCIncrease = new SalaryFieldConfig();
        TTCIncrease.setField("TTCIncrease");
        TTCIncrease.setFieldName("年度目标总现金（TTC）涨幅");
        TTCIncrease.setType(1);
        TTCIncrease.setFrontShowName("年度目标总现金（TTC）（元/年）");
        TTCIncrease.setShouldMeasurement(true);
        defaultConfig.setTTCIncrease(TTCIncrease);

        SalaryFieldConfig shareIncrease = new SalaryFieldConfig();
        shareIncrease.setField("shareIncrease");
        shareIncrease.setFieldName("股票期权涨幅");
        shareIncrease.setType(1);
        shareIncrease.setFrontShowName("股票期权（元/年）");
        shareIncrease.setShouldMeasurement(true);
        defaultConfig.setShareIncrease(shareIncrease);

        SalaryFieldConfig totalIncomeIncrease = new SalaryFieldConfig();
        totalIncomeIncrease.setField("totalIncomeIncrease");
        totalIncomeIncrease.setFieldName("年度目标总收入涨幅");
        totalIncomeIncrease.setType(1);
        totalIncomeIncrease.setFrontShowName("年度目标总收入（TP）（元/年）");
        totalIncomeIncrease.setShouldMeasurement(true);
        defaultConfig.setTotalIncomeIncrease(totalIncomeIncrease);

        SalaryFieldConfig otherSalaryMeasurePrice = new SalaryFieldConfig();
        otherSalaryMeasurePrice.setField("otherSalaryMeasurePrice");
        otherSalaryMeasurePrice.setFieldName("补助/其他薪资（元/年）");
        otherSalaryMeasurePrice.setType(2);
        otherSalaryMeasurePrice.setFrontShowName("补助/其他薪资（元/年）");
        otherSalaryMeasurePrice.setShouldMeasurement(false);
        defaultConfig.setOtherSalaryMeasurePrice(otherSalaryMeasurePrice);

        SalaryFieldConfig groupShareMeasurePrice = new SalaryFieldConfig();
        groupShareMeasurePrice.setField("groupShareMeasurePrice");
        groupShareMeasurePrice.setFieldName("集团股票期权测算价格（元/股）");
        groupShareMeasurePrice.setType(2);
        groupShareMeasurePrice.setFrontShowName("集团股票期权测算价格（元/股）");
        groupShareMeasurePrice.setShouldMeasurement(false);
        defaultConfig.setGroupShareMeasurePrice(groupShareMeasurePrice);

        SalaryFieldConfig houseShareMeasurePrice = new SalaryFieldConfig();
        houseShareMeasurePrice.setField("houseShareMeasurePrice");
        houseShareMeasurePrice.setFieldName("房产股票期权测算价格（元/股）");
        houseShareMeasurePrice.setType(2);
        houseShareMeasurePrice.setFrontShowName("房产股票期权测算价格（元/股）");
        houseShareMeasurePrice.setShouldMeasurement(false);
        defaultConfig.setHouseShareMeasurePrice(houseShareMeasurePrice);

        return defaultConfig;
    }

    // 测算页面字段排序
    public List<SalaryFieldConfig> queryListSortForMeasurementPage() {
        List<SalaryFieldConfig> fieldConfigList = new ArrayList<>();
        if (!Objects.isNull(basicSalaryIncrease)) {
            fieldConfigList.add(basicSalaryIncrease);
        }
        if (!Objects.isNull(performanceIncrease)) {
            fieldConfigList.add(performanceIncrease);
        }
        if (!Objects.isNull(otherSalaryMeasurePrice)) {
            fieldConfigList.add(otherSalaryMeasurePrice);
        }
        if (!Objects.isNull(yearEndBonusIncrease)) {
            fieldConfigList.add(yearEndBonusIncrease);
        }
        if (!Objects.isNull(TTCIncrease)) {
            fieldConfigList.add(TTCIncrease);
        }
        if (!Objects.isNull(shareIncrease)) {
            fieldConfigList.add(shareIncrease);
        }
        if (!Objects.isNull(totalIncomeIncrease)) {
            fieldConfigList.add(totalIncomeIncrease);
        }
        if (!Objects.isNull(groupShareMeasurePrice)) {
            fieldConfigList.add(groupShareMeasurePrice);
        }
        if (!Objects.isNull(houseShareMeasurePrice)) {
            fieldConfigList.add(houseShareMeasurePrice);
        }
        return fieldConfigList;
    }

    // 配置页面字段排序
    public List<SalaryFieldConfig> queryListSortForConfig() {
        List<SalaryFieldConfig> fieldConfigList = new ArrayList<>();
        if (!Objects.isNull(basicSalaryIncrease)) {
            fieldConfigList.add(basicSalaryIncrease);
        }
        if (!Objects.isNull(performanceIncrease)) {
            fieldConfigList.add(performanceIncrease);
        }
        if (!Objects.isNull(yearEndBonusIncrease)) {
            fieldConfigList.add(yearEndBonusIncrease);
        }
        if (!Objects.isNull(TTCIncrease)) {
            fieldConfigList.add(TTCIncrease);
        }
        if (!Objects.isNull(shareIncrease)) {
            fieldConfigList.add(shareIncrease);
        }
        if (!Objects.isNull(totalIncomeIncrease)) {
            fieldConfigList.add(totalIncomeIncrease);
        }
        if (!Objects.isNull(otherSalaryMeasurePrice)) {
            fieldConfigList.add(otherSalaryMeasurePrice);
        }
        if (!Objects.isNull(groupShareMeasurePrice)) {
            fieldConfigList.add(groupShareMeasurePrice);
        }
        if (!Objects.isNull(houseShareMeasurePrice)) {
            fieldConfigList.add(houseShareMeasurePrice);
        }
        return fieldConfigList;
    }

    // 获取需要测算的字段
    public static Map<String, String> getMeasurementField2FrontName() {
        return SalaryMeasurementConfig.getDefaultConfig().queryListSortForMeasurementPage()
                .stream()
                .filter(SalaryFieldConfig::getShouldMeasurement)
                .collect(Collectors.toMap(SalaryFieldConfig::getField, SalaryFieldConfig::getFrontShowName));
    }
}
